package com.runshu.newsmartark.adapter;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.runshu.newsmartark.R;
import com.runshu.newsmartark.entity.UserInfoEntity;

import java.util.List;

/**
 * Demo class
 *
 * @author yu
 * @date 2020/8/27
 * @decs：
 */

public class MyFaceAdapter extends BaseQuickAdapter<UserInfoEntity, BaseViewHolder> {
    public MyFaceAdapter(@Nullable List<UserInfoEntity> data) {
        super(R.layout.item_face_manager, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserInfoEntity item) {
        helper.setText(R.id.tv_no, String.valueOf(helper.getAdapterPosition() + 1));
        helper.setText(R.id.tv_name, item.getUserName());
        helper.setText(R.id.tv_code, item.getUserCode());
        helper.setText(R.id.tv_create_date, item.getCreateTime());
        helper.setImageBitmap(R.id.img_head,stringToBitmap(item.getFaceCode()));
//        helper.setText(R.id.tv_title, item.getOffice()+" / "+item.getPosition() );
    }

    public Bitmap getBitmapFromByte(byte[] temp){
        if(temp != null){
            Bitmap bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length);
            return bitmap;
        }else{
            return null;
        }
    }

    public Bitmap stringToBitmap(String string) {
        // 将字符串转换成Bitmap类型
        Bitmap bitmap = null;
        try {
            byte[] bitmapArray;
            bitmapArray = Base64.decode(string, Base64.URL_SAFE);
            bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,
                    bitmapArray.length);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }
}